package com.share.introspection;

import java.lang.module.ModuleDescriptor;
import java.util.Set;

/**
 * @author caifan
 * @since 2021/12/15
 * @description: 内省
 */
public class Introspection {

    public static void main(String... args) {
        Module module = String.class.getModule();
        String moduleName = module.getName();
        //module name:java.base
        System.out.println("module name:" + moduleName);

        // 模块中对应的包
        Set<String> packages = module.getPackages();
        System.out.println("package in module:" + packages);

        ModuleDescriptor descriptor = module.getDescriptor();
        String descriptorName = descriptor.name();
        // 模块描述 同module.getName
        System.out.println("descriptorName:" + descriptorName);

        // 同module.getPackages()
        Set<String> packages1 = descriptor.packages();
        System.out.println("descriptor packages1:" + packages1);

        // 被暴露导出的所有包
        Set<ModuleDescriptor.Exports> exports = descriptor.exports();
        System.out.println("exports:" + exports);

        // All services used by this module
        Set<String> uses = descriptor.uses();
        System.out.println("uses:" + uses);
    }
}
